﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class web_Controls_page_top_banner : System.Web.UI.UserControl
{
    Common comm = new Common();
    public DataTable dtt;
    public string sBanner = "<a href='../../Default.aspx'><img src='../../web/images/vl-banner.gif' width='1024px' height='200px'/></a>";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!(String.IsNullOrEmpty(Session["id_page"].ToString())))
            {
                dtt = comm.getDataTable("select * from CreatePages_page where id_page=" + Session["id_page"].ToString());
                if (dtt.Rows.Count > 0)
                {
                    if(!(String.IsNullOrEmpty(dtt.Rows[0]["banner_path"].ToString())))
                        sBanner = getViewFlash("1024px", "200px", dtt.Rows[0]["banner_path"].ToString());
                }
            }
        }
    }
    private string getViewFlash(string width, string height, string url)
    {
        string[] kiemtra = url.Split('.');
        string chuoimatna = "jpg,jpeg,png,bmp,gif";
        string fileType= kiemtra.GetValue(kiemtra.Length - 1).ToString().ToLower();
        if (chuoimatna.Contains(fileType)==true) //neu dung nghĩa là đây là file ảnh

            return "<a href='../../Default.aspx'><img src='" + url + "' height='" + height + "' width='" + width + "' /></a>";
        else
            return "<a href='../../Default.aspx'> <object  width=" + width + " height=" + height + " type='application/x-shockwave-flash' data='" + url + "'><param name='movie' value='" + url + "'/><param name='WMode' value='Transparent'/></object></a>";
    }
}
